home *** CD-ROM | disk | FTP | other *** search
/ Aminet 38 / Aminet 38 (2000)(Schatztruhe)[!][Aug 2000].iso / Aminet / util / moni / Scout-src.lha / src / objects / scout_assigns.c < prev    next >
Encoding:
C/C++ Source or Header  |  2000-03-09  |  7.5 KB  |  235 lines

  1. /**
  2.  * Scout - The Amiga System Monitor
  3.  *
  4.  *------------------------------------------------------------------
  5.  *
  6.  * This program is free software; you can redistribute it and/or modify
  7.  * it under the terms of the GNU General Public License as published by
  8.  * the Free Software Foundation; either version 2 of the License, or
  9.  * any later version.
  10.  *
  11.  * This program is distributed in the hope that it will be useful,
  12.  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13.  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  14.  * GNU General Public License for more details.
  15.  *
  16.  * You should have received a copy of the GNU General Public License
  17.  * along with this program; if not, write to the Free Software
  18.  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  19.  *
  20.  * You must not use this source code to gain profit of any kind!
  21.  *
  22.  *------------------------------------------------------------------
  23.  *
  24.  * @author Andreas Gelhausen
  25.  * @author Richard Körber <rkoerber@gmx.de>
  26.  */
  27.  
  28.  
  29.  
  30. #include "scout_assigns.h"
  31.  
  32. extern struct ExecBase     *SysBase;
  33. extern struct DosLibrary   *DOSBase;
  34.  
  35. int  asscnt;
  36.  
  37. #define  AssPuddleSize  1024
  38. #define  AssThreshSize  512
  39.  
  40. APTR AssPool = NULL;
  41.  
  42. __asm LONG asslist_dspfunc(register __a2 char **array, register __a1 struct AssEntry *assentry, register __a0 struct Hook *hook) {
  43.    if (assentry) {
  44.       *array++ = assentry->ass_address;
  45.       *array++ = assentry->ass_name;
  46.       *array++ = assentry->ass_path;
  47.       *array   = NULL;
  48.    } else {
  49.       *array++ = ESC "bAddress";
  50.       *array++ = ESC "bName";
  51.       *array++ = ESC "bPath";
  52.       *array++ = NULL;
  53.    }
  54.    return(0);
  55. }
  56.  
  57. struct Hook asslist_dsphook = {
  58.  {NULL, NULL},
  59.  (ULONG (* )())asslist_dspfunc,
  60.  NULL, NULL
  61. };
  62.  
  63. void FreeAssigns (void) {
  64.    if (AssPool) {
  65.       if (AP_Scout) {
  66.          set (asstext,MUIA_Text_Contents,"");
  67.          DoMethod (asslist,MUIM_List_Clear);
  68.       }
  69.       AsmDeletePool (AssPool,SysBase);
  70.       AssPool = NULL;
  71.    }
  72. }
  73.  
  74. int GetAssigns (struct AssEntry **first) {
  75.    struct   AssEntry       *assentry,*previous = NULL;
  76.    struct   DosList        *dev;
  77.    struct   AssignList     *list;
  78.    struct   FileInfoBlock  *infoBlock;
  79.  
  80.    int asscnt = 0;
  81.    *first = 0;
  82.  
  83.    if (! AssPool)
  84.       AssPool = AsmCreatePool (MEMF_ANY|MEMF_CLEAR,AssPuddleSize,AssThreshSize,SysBase);
  85.  
  86.    dev = DOSLIST;
  87.  
  88.    if (clientstate) {
  89.       char  tmpbuffer[256];
  90.  
  91.       if (SendDaemon ("GetAssList")) {
  92.          while ((assentry = AsmAllocPooled (AssPool,sizeof (struct AssEntry),SysBase)) \
  93.            && (ReceiveDecodedEntry ((UBYTE *) assentry, sizeof (struct AssEntry) - 4)) \
  94.            && (sgets (client_socket, tmpbuffer, 256))) {
  95.  
  96.             if (assentry->ass_path = AsmAllocPooled (AssPool, strlen (tmpbuffer) + 1, SysBase)) {
  97.                strncpy (assentry->ass_path, tmpbuffer, strlen (tmpbuffer) + 1);
  98.             }
  99.  
  100.             IsHex (assentry->ass_address, (long *) &assentry->ass_adr);
  101.  
  102.             if (! *first)
  103.                *first = assentry;
  104.             if (previous)
  105.                previous->ass_next = assentry;
  106.  
  107.             asscnt++;
  108.             previous = assentry;
  109.          }
  110.       }
  111.    } else {
  112.       if (infoBlock = AllocMem (sizeof (struct FileInfoBlock), MEMF_ANY|MEMF_CLEAR)) {
  113.          while ((dev != 0) && (assentry = AsmAllocPooled (AssPool,sizeof (struct AssEntry),SysBase))) {
  114.             if ((dev->dol_Type == DLT_DIRECTORY) || (dev->dol_Type == DLT_LATE) || (dev->dol_Type == DLT_NONBINDING)) {
  115.                if (! *first)
  116.                   *first = assentry;
  117.                if (previous)
  118.                   previous->ass_next = assentry;
  119.    
  120.                assentry->ass_adr = (char *) dev;
  121.                sprintf (assentry->ass_address, "$%08x", dev);
  122.                strncpy (assentry->ass_name, (char const *) ((dev->dol_Name)<<2)+1, 20);
  123.    
  124.                if (Examine (dev->dol_Lock, infoBlock)) {
  125.                   tmpstr[0] = '\0';
  126.                   NameFromLock (dev->dol_Lock, tmpstr, PATHLENGTH);
  127.    
  128.                   if ((dev->dol_Type == DLT_DIRECTORY) && (assentry->ass_path = AsmAllocPooled (AssPool, strlen (tmpstr) + 1,SysBase))) {
  129.                      strcpy (assentry->ass_path, tmpstr);
  130.                   } else if ((dev->dol_Type == DLT_LATE) && (assentry->ass_path = AsmAllocPooled (AssPool, strlen (dev->dol_misc.dol_assign.dol_AssignName) + 3,SysBase))) {
  131.                      sprintf (assentry->ass_path, "<%s>", dev->dol_misc.dol_assign.dol_AssignName);
  132.                   } else if ((dev->dol_Type == DLT_NONBINDING) && (assentry->ass_path = AsmAllocPooled (AssPool, strlen (dev->dol_misc.dol_assign.dol_AssignName) + 3,SysBase))) {
  133.                      sprintf (assentry->ass_path, "[%s]", dev->dol_misc.dol_assign.dol_AssignName);
  134.                   }
  135.                }
  136.                asscnt++;
  137.    
  138.                previous = assentry;
  139.                list = dev->dol_misc.dol_assign.dol_List;
  140.    
  141.                while ((list) && (assentry = AsmAllocPooled (AssPool,sizeof (struct AssEntry),SysBase))) {
  142.                   if (previous)
  143.                      previous->ass_next = assentry;
  144.    
  145.                   assentry->ass_adr = (char *) (list->al_Lock);
  146.                   sprintf (assentry->ass_address, "$%08x", (char *) (list->al_Lock<<2));
  147.                   strcpy (assentry->ass_name, (char const *) ((dev->dol_Name)<<2)+1);
  148.    
  149.                   if (Examine (list->al_Lock, infoBlock)) {
  150.                      tmpstr[0] = '\0';
  151.                      NameFromLock (list->al_Lock, tmpstr, PATHLENGTH);
  152.    
  153.                      if ((dev->dol_Type == DLT_DIRECTORY) && (assentry->ass_path = AsmAllocPooled (AssPool, strlen (tmpstr) + 7,SysBase))) {
  154.                         sprintf (assentry->ass_path, " +  %s", tmpstr);
  155.                      }
  156.                   }
  157.                   asscnt++;
  158.    
  159.                   previous = assentry;
  160.                   list = (struct AssignList *) (list->al_Next);
  161.                }
  162.             }
  163.             dev = (struct DosList *)((dev->dol_Next)<<2);
  164.          }
  165.          FreeMem (infoBlock, sizeof (struct FileInfoBlock));
  166. //    infoBlock = NULL;
  167.       }
  168.    }
  169.    return (asscnt);
  170. }
  171.  
  172. void PrintAssigns (char *filename) {
  173.    int   i=1;
  174.    BPTR  handle;
  175.    struct AssEntry *entryp;
  176.  
  177.    handle = HandlePrintStart (filename);
  178.    if ((handle) && (PrintOneLine (handle, "\n  Address  Name       Path\n\n"))) {
  179.       if (! WI_Assigns) {
  180.          i = GetAssigns (&entryp);
  181.       }
  182.       if (i) {
  183.          for (i=0;;i++) {
  184.             if (WI_Assigns)
  185.                DoMethod (asslist,MUIM_List_GetEntry,i,&entryp);
  186.             if (!entryp) break;
  187.  
  188.             sprintf (tmpstr2, " %9ls %-10ls %ls\n", entryp->ass_address, entryp->ass_name, entryp->ass_path);
  189.             if (! (PrintOneLine (handle, tmpstr2)))
  190.                break;
  191.  
  192.             if (! WI_Assigns)
  193.                entryp = entryp->ass_next;
  194.          }
  195.       }
  196.    }
  197.    HandlePrintStop();
  198. }
  199.  
  200. void ShowAssigns (void) {
  201.    struct AssEntry *ass;
  202.  
  203.    ApplicationSleep();
  204.    set (asslist,MUIA_List_Quiet,TRUE);
  205.    set (asslist,MUIA_List_CompareHook,asslist_cmphook_ptr);
  206.    set (BT_AssRemove, MUIA_Disabled, TRUE);
  207.  
  208.    FreeAssigns();
  209.    asscnt = GetAssigns (&ass);
  210.  
  211.    while (ass) {
  212.       InsertSortedEntry (asslist, (APTR *) &ass);
  213.       ass = ass->ass_next;
  214.    }
  215.  
  216.    SetCountText (asscount, asscnt);
  217.    AwakeApplication();
  218.    set (asslist,MUIA_List_Quiet,FALSE);
  219. }
  220.  
  221. void SendAssList (void) {
  222.    struct AssEntry *ass;
  223.  
  224.    FreeAssigns();
  225.    asscnt = GetAssigns (&ass);
  226.  
  227.    while (ass) {
  228.       SendEncodedEntry ((UBYTE *) ass, sizeof (struct AssEntry) - 4);
  229.       SendClient ((UBYTE *) ass->ass_path);
  230.       ass = ass->ass_next;
  231.    }
  232.    FreeAssigns();
  233. }
  234.  
  235.